GilRs - Game Input Library for Rust
GilRs abstract platform specific APIs to provide unified interfaces for working with gamepads.
Main features:
- Unified gamepad layout—buttons and axes are represented by familiar names
- Support for SDL2 mappings including
SDL_GAMECONTROLLERCONFIGenvironment variable which Steam uses - Hotplugging—GilRs will try to assign new IDs for new gamepads and reuse same ID for gamepads which reconnected
- Force feedback (rumble)
- Power information (is gamepad wired, current battery status)
Example
use ;
let mut gilrs = new.unwrap;
// Iterate over all connected gamepads
for in gilrs.gamepads
let mut active_gamepad = None;
loop
Supported features
| Input | Hotplugging | Force feedback | |
|---|---|---|---|
| Linux | ✓ | ✓ | ✓ |
| Windows (XInput) | ✓ | ✓ | ✓ |
| OS X | ✓ | ✓ | ✕ |
| Wasm | ✓ | ✓ | n/a |
| Android | ✕ | ✕ | ✕ |
Controller layout
Mappings
GilRs use SDL-compatible controller mappings to fix on Linux legacy drivers that doesn't follow
Linux Gamepad API and to provide
unified button layout for platforms that doesn't make any guarantees about it. The main source
is SDL_GameControllerDB, but library also
support loading mappings from environment variable SDL_GAMECONTROLLERCONFIG (which Steam
use).
Cargo features
serde-serialize- enable deriving of serde'sSerializeandDeserializefor various types.
Platform specific notes
Linux
On Linux, GilRs read (and write, in case of force feedback) directly from appropriate
/dev/input/event* file. This mean that user have to have read and write access to this file.
On most distros it shouldn't be a problem, but if it is, you will have to create udev rule.
To build GilRs, you will need pkg-config and libudev .pc file. On some
distributions this file is packaged in separate archive (for example libudev-dev in Debian).
Wasm
Wasm implementation uses stdweb, or wasm-bindgen with the wasm-bindgen feature.
For stdweb, you will need cargo-web to build gilrs for
wasm32-unknown-unknown. For wasm-bindgen, you will need the wasm-bindgen cli or a tool like
wasm-pack.
Unlike other platforms, events are only generated when you call Gilrs::next_event().